package com.example.park_management.controller;

import com.example.park_management.entity.Dept;
import com.example.park_management.result.Result;
import com.example.park_management.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@CrossOrigin

@RestController
@RequestMapping("/dept")
public class DeptManagement_zyz {
    //查询
    @Autowired
    private DeptService deptService;

    @GetMapping("/dept_get")
    public Result<List<Dept>> getDept() {


        List<Dept> result = deptService.getDeptById();
        if (result != null) {
            log.info("查询部门数据:{}",result);
            return Result.success(result);
        } else {
            return Result.error("No department found with the given id");
        }
    }
@GetMapping("/deptDelete")
    public Result deptDelete(@RequestParam Integer id) {
            boolean isSuccess = deptService.deleteDept(id);
            if (isSuccess) {
                return Result.success();
            } else {
                return Result.error("Failed to delete department with id " + id);
            }
    }


}
